# def guanjia(game):
#     def inner():
#         print("打开外挂")
#         game()
#         print("关闭外挂")
#     return inner      # 注意此处返回的内部函数inner，不要加小括号
#
# def play_dnf():
#     print("The game I play is DNF")
#
# def play_lol():
#     print("The game I play is LOL")
#
#
# play_dnf=guanjia(play_dnf) # 让管家把游戏重新封装一遍，增加了打开关闭外挂的功能
# play_lol=guanjia(play_lol)
# play_dnf()   #此时运行的是管家给的内部函数inner
# play_lol()


# def guanjia(game):
#     def inner():
#         print("打开外挂")
#         game()
#         print("关闭外挂")
#     return inner      # 注意此处返回的内部函数inner，不要加小括号
# @guanjia  #@guanjia相当于play_dnf=guanjia(play_dnf)
# def play_dnf():
#     print("The game I play is DNF")
# @guanjia
# def play_lol():
#     print("The game I play is LOL")
#
# play_dnf()   #此时运行的是管家给的内部函数inner
# play_lol()


# def guanjia(game):
#     def inner(*args,**kwargs):
# # *args,**kwargs表示接受任意数量、任意类型的参数，并将它们打包成元组和字典
#         print("打开外挂")
#         game(*args,**kwargs)
# # 将inner函数接收到的可变参数args和关键字参数kwargs打散成位置参数和关键字参数传递给game函数。
#         print("关闭外挂")
#     return inner      # 注意此处返回的内部函数inner，不要加小括号
#
# @guanjia  #相当于play_dnf=guanjia(play_dnf)
# def play_dnf(username,password):
#     print("The game I play is DNF\n","username is","password is",username,password)
# @guanjia
# def play_lol(username,password,area):
#     print("The game I play is LOL\n","username is",username,"password is",password,"area is",area)
#
# play_dnf("admin","123456")   #此时运行的是管家给的内部函数inner
# play_lol("admin1","456789","Ionia")


# def guanjia(game):
#     def inner(*args,**kwargs):
#         print("打开外挂")
#         ret=game(*args,**kwargs)
#         print("关闭外挂")
#         return ret
#     return inner      # 注意此处返回的内部函数inner，不要加小括号
#
# @guanjia
# def play_dnf(username,password):
#     print("The game I play is DNF",username,password)
#     return "通常会返回一些返回值"
# @guanjia
# def play_lol(username,password,area):
#     print("The game I play is LOL",username,password,area)
#     return "通常会返回一些返回值"
#
# ret=play_dnf("admin","123456")   #此时运行的是管家给的内部函数inner
# print(ret)
# ret=play_lol("admin1","456789","Ionia")
# print(ret)


#
# def wrapper1(fn):#target:wrapper2.inner
#     def inner(*args,**kwargs):
#         print("wrapper1 in")
#         ret=fn(*args,**kwargs)
#         print("wrapper1 out")
#         return ret
#     return inner
#
#
# def wrapper2(fn):#fn:target
#     def inner(*args, **kwargs):
#         print("wrapper2 in")
#         ret = fn(*args, **kwargs)
#         print("wrapper2 out")
#         return ret
#     return inner
#
# @wrapper1 #target=wrapper1(wrapper2.inner) -> target:wrapper1.inner
# @wrapper2 #target=wrapper2(target) -> target:wrapper2.inner
# def target():
#     print("目标函数")
# target()
# #wrapper1 是外层装饰器，wrapper2 是内层装饰器。
# # 目标函数 target 会先经过 wrapper2 的装饰，再经过 wrapper1 的装饰。
# # (wrapper1 (wrapper2 target wrapper2) wrapper1)

#
# login_flag = False
#
#
# def login_verify(fn):
#     def inner(*args, **kwargs):
#         global login_flag
#         if not login_flag:  # if login_flag==False
#             print("用户未登录")
#             while (1):
#                 username = input(">>>")
#                 password = input(">>>")
#                 if username == "admin" and password == "123":
#                     print("登录成功")
#                     login_flag = True
#                     break
#                 else:
#                     print("用户名或密码错误")
#         # ret = fn(*args, **kwargs)
#         # return ret
#         return fn(*args, **kwargs)
#
#     return inner
#
#
# @login_verify
# def add():
#     print("添加员工信息")
#
#
# @login_verify
# def delete():
#     print("删除员工信息")
#
#
# @login_verify
# def upd():
#     print("更新员工信息")
#
#
# @login_verify
# def search():
#     print("查询员工信息")
#
#
# add()
# delete()
# upd()
# search()
